﻿using System;
using System.Collections.Generic;
using System.Text;
using Hangfire;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;

namespace Helpers
{
    public class StartHangfireServerStartupFilter : IStartupFilter
    {
        public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
        {
            return app =>
            {
                var options = app.ApplicationServices.GetService<HangfireHelperOptions>();
                if (options.StartHangfireDashboard)
                {
                    app.UseHangfireDashboard();
                }
                options.SetupJobs?.Invoke();
                next(app);
            };
        }
    }
}
